package fun

import (
	"errors"
	"fmt"
)

type Printer func(contents string)(n int,err error)

func printTostd(contents string)(bytesNum int ,err error)  {
	return fmt.Println(contents)
}

func FuncDemo()  {
	var p Printer
	p=printTostd
	p("go fun")
	printTostd("aaa")
}

func FunNoName() func(int ,int )int {
	op := func(x, y int) int {
		return x + y
	}
	return op
}


//------------------------------------------------------------
type Operate func(x, y int) int
type calculateFunc func(x int, y int) (int, error)

func calculate(x int, y int, op Operate) (int, error) {
  if op == nil {
    return 0, errors.New("invalid operation")
  }
  return op(x, y), nil
}

func GenCalculator(op Operate) calculateFunc {
  return func(x int, y int) (int, error) {
    if op == nil {
      return 0, errors.New("invalid operation")
    }
    return op(x, y), nil
  }
}
//-----------



func ModifyDemo() {
  array1 := [3]string{"a", "b", "c"}
  fmt.Printf("The array: %v\n", array1)
  array2 := modifyArray(array1)
  fmt.Printf("The modified array: %v\n", array2)
  fmt.Printf("The original array: %v\n", array1)
}

func modifyArray(a [3]string) [3]string {
  a[1] = "x"
  return a
}



